package com.michael.study.component.fragment

import android.os.Bundle
import android.os.Handler
import android.os.Message
import androidx.appcompat.app.AppCompatActivity
import com.michael.study.component.R
import kotlinx.android.synthetic.main.activity_view_pager.*

class ViewPagerActivity : AppCompatActivity() {

    private var mHandler = object  : Handler(){
        override fun handleMessage(msg: Message) {
            super.handleMessage(msg)
            when(msg.what) {
                1000 -> {
                    mTitles.remove("A")
                    mAdapter.notifyDataSetChanged()
                }
            }
        }
    }

    private lateinit var mAdapter : BAdapter
    private var mTitles = ArrayList<String>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_view_pager)

        mTitles.add("A")
        mTitles.add("B")
        mTitles.add("C")
        mTitles.add("D")
        mAdapter = BAdapter(supportFragmentManager,mTitles)
        view_pager.adapter = mAdapter
        tab_layout.setupWithViewPager(view_pager)

        //mHandler.sendEmptyMessageDelayed(1000,3000)

    }
}